package com.example.exam.authorization.dao;

import com.example.exam.authorization.model.AuthorizationBean;
import com.example.exam.db.BaseDao;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

@Repository
public class AuthorizationDao extends BaseDao<AuthorizationBean,Integer> {
    /**
     * @Description:查询用户岗位名
     * @Param: [id]
     * @return: com.example.exam.authorization.model.AuthorizationBean
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public AuthorizationBean findPost(Integer id){

        try{
            String sql="SELECT NAME AS post FROM staff_post sp WHERE sp.id IN(SELECT post FROM staff_info si WHERE si.id IN (SELECT staff_id FROM staff_user WHERE user_id=?))";
            return getJtl().queryForObject(sql,new BeanPropertyRowMapper<AuthorizationBean>(AuthorizationBean.class),id);
        }catch (Exception e){
            return null;
        }
    } /**
     * @Description:查看用户是否为超级管理员
     * @Param: [id]
     * @return: com.example.exam.authorization.model.AuthorizationBean
     * @Author: xhw
     * @Date: 2021/7/26
     */
    public AuthorizationBean findRole(Integer id){
        try{
            String sql="SELECT COUNT(*) AS num FROM sys_user_role WHERE user_id=? AND role_id=1 AND state=1";
            return getJtl().queryForObject(sql,new BeanPropertyRowMapper<AuthorizationBean>(AuthorizationBean.class),id);
        }catch (Exception e){
            return null;
        }
    }
}
